<template>
  <div class="environment-comp">
    <div class="title-content">
      <p class="title">环境监测</p>
    </div>
    <el-dropdown placement="bottom-start" @command="handleCommand">
      <div class="project-select-container">
        <span class="project-name">{{ currentName }}</span>
        <i class="el-icon-arrow-down el-icon--right"></i>
      </div>
      <el-dropdown-menu
        class="environment-comp-drop"
        slot="dropdown">
        <el-dropdown-item
          v-for="(item, index) in list"
          :command="item.projectId"
          :key="index">
          {{ item.projectName }}
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <div class="details">
      <div class="details_left">
        <div class="pm">
          <div class="g-wave"></div>
          <div class="bg"></div>
          <p class="value">16.67</p>
          <p class="unit">PM2.5</p>
        </div>
        <div class="pm pm-bottom">
          <div class="g-wave"></div>
          <p class="value">16.67</p>
          <p class="unit">PM10</p>
        </div>
      </div>
      <ul class="details_right">
        <li class="detail-item">
          <div class="item-icon">
            <i class="iconfont iconyinliang"></i>
            <span>噪声</span>
          </div>
          <span>5DB</span>
        </li>
        <li class="detail-item">
          <div class="item-icon">
            <i class="iconfont iconfengsu"></i>
            <span>风速</span>
          </div>
          <span>2.9M/S</span>
        </li>
        <li class="detail-item">
          <div class="item-icon">
            <i class="iconfont iconwendu"></i>
            <span>温度</span>
          </div>
          <span>26℃</span>
        </li>
        <li class="detail-item">
          <div class="item-icon">
            <i class="iconfont iconshidu"></i>
            <span>湿度</span>
          </div>
          <span>2.9M/S</span>
        </li>
        <li class="detail-item">
          <div class="item-icon">
            <i class="iconfont iconfengxiang"></i>
            <span>风向</span>
          </div>
          <span>南风</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  name: 'environmentComp',
  data() {
    return {
      // 当前选择的项目id
      currentId: '',
      // 当前项目名
      currentName: ''
    };
  },
  computed: {
    // 项目列表信息
    list() {
      return this.$store.state.projectInfo || [];
    }
  },
  watch: {
    list: {
      deep: true,
      immediate: true,
      handler: function (data) {
        this.currentId = data[0] && data[0].projectId || '';
      }
    },
    currentId(id) {
      const curentProject = this.list.find(item => (
        item.projectId === id
      ));
      this.currentName = curentProject.projectName || '';
    }
  },
  methods: {
    /**
     * 切换项目
     * @param  id {String} 项目id
     */
    handleCommand(id) {
      this.currentId = id;
    },
    /**
     * 获取环境详情
     */
    getDetails() {}
  }
};
</script>

<style scoped lang="scss">
@import '../../assets/styles/main';

.environment-comp {
  width: 100%;
  .title-content {
    height: 30px;
    overflow: hidden;
    text-align: right;
    margin-bottom: 20px;
  }
  .title {
    width: calc(100% - 10px);
    background: linear-gradient(to left, #18235f, #414d96);
    padding: 5px 15px;
    font-size: 15px;
    margin-bottom: 20px;
    color: $mainColor;
    text-align: right;
    border-radius: 13px 10px 10px 0;
    position: relative;
    display: inline-block;
    &:after {
      content: '';
      position: absolute;
      left: -14px;
      top: 11px;
      width: 0;
      height: 0;
      border-width: 5px 16px;
      border-style: solid;
      border-color: #414d96 transparent transparent #414d96;
      border-radius: 6px 15px 0 0;
      z-index: 1;
      transform: rotate(-65deg);
    }
  }
  .project-select-container {
    width: 100%;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #ffff;
    .project-name {
      display: inline-block;
      width: 380px;
      height: 100%;
      background-color: $inputBgRbga ;
      border-radius: 8px 0 0 8px;
      padding: 10px;
    }
    i {
      width: 40px;
      height: 40px;
      font-size: 18px;
      background-color: rgb(56, 56, 96);
      margin: 0;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
  .details {
    width: 100%;
    height: 210px;
    padding: 25px 0;
    display: flex;
    justify-content: space-between;
    &_left {
      width: 80px;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      .pm {
        width: 75px;
        height: 75px;
        border-radius: 50%;
        background: linear-gradient(0deg, #3b5fe9 60%, transparent);
        position: relative;
        color: #fff;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        overflow: hidden;
        border: 1px solid rgba(59, 95, 233, .2);
        &.pm-bottom {
          background: linear-gradient(0deg, #1a9f7f 60%, transparent);
          border: 1px solid rgba(26, 159, 127, .2);
          .g-wave {
            animation: move 5s linear infinite;
          }
        }
        .g-wave {
          position: absolute;
          width: 75px;
          height: 75px;
          background: rgba(255, 255, 255, 0.4);
          border-radius: 45% 47% 44% 42%;
          bottom: 62px;
          z-index: 1;
          animation: move 3s linear infinite;
        }
        .bg {

        }
        .value {
          font-size: 18px;
        }
        .unit {
          font-size: 12px;
        }
      }
    }
    &_right {
      width: 320px;
      height: 160px;
      overflow: auto;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      .detail-item {
        width: 155px;
        height: 45px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px;
        background: $inputBgRbga;
        color: #fff;
        border-radius: 5px;
        .item-icon {
          i {
            color: #fff;
            padding: 5px;
            border-radius: 4px;
            &.iconyinliang {
              background-color: #e5452b;
            }
            &.iconfengsu {
              background-color: #5373ea;
            }
            &.iconwendu {
              background-color: #3ecb90;
            }
            &.iconshidu {
              background-color: #38a9fc;
            }
            &.iconfengxiang {
              background-color: #d9be1d;
            }
          }
          span {
            color: $mainColor;
          }
        }
      }
    }
  }
  @keyframes move {
    100% {
      transform: rotate(-360deg);
    }
  }
}
</style>
